import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    token: '',
    userInfo: JSON.parse(sessionStorage.getItem("userInfo")),
    company: JSON.parse(sessionStorage.getItem("company")),
    student: JSON.parse(sessionStorage.getItem("student")),
  },
  mutations: {
    //set
    SET_TOKEN: (state, token) => {
      state.token = token
      localStorage.setItem("token", token)
    },
    SET_USERINFO: (state, userInfo) => {
      state.userInfo = userInfo
      sessionStorage.setItem("userInfo", JSON.stringify(userInfo))
    },
    SET_COMPANY: (state, company) => {
      state.company = company
      sessionStorage.setItem("company", JSON.stringify(company))
    },
    SET_STUDENT: (state, student) => {
      state.student = student
      sessionStorage.setItem("student", JSON.stringify(student))
    },

    REMOVE_INFO: (state) => {
      state.token = ''
      state.userInfo = {}
      state.student = {}
      state.company = {}
      localStorage.setItem("token", '')
      sessionStorage.setItem("userInfo", JSON.stringify(''))
      sessionStorage.setItem("student", JSON.stringify(''))
      sessionStorage.setItem("company", JSON.stringify(''))
    },
  },
  getters: {
    //get
    getUser: state => {
      return state.userInfo
    },
    getCompany: state => {
      return state.company
    },
    getStudent: state => {
      return state.student
    }
  },
  actions: {
  },
  modules: {},
});
